package com.hhkj.admin.conf.service.biz.impl;

import cn.hutool.core.bean.BeanUtil;
import com.hhkj.admin.common.annotation.ClearRedis;
import com.hhkj.admin.common.annotation.UseRedis;
import com.hhkj.admin.conf.common.cont.ConfConst;
import com.hhkj.admin.conf.model.extend.WithdrawalLimit;
import com.hhkj.admin.conf.model.req.WithdrawalLimitReq;
import com.hhkj.admin.conf.model.res.WithdrawalLimitRes;
import com.hhkj.admin.conf.service.base.impl.ConfServiceImpl;
import com.hhkj.admin.conf.service.biz.WithdrawalLimitBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class WithdrawalLimitBizServiceImpl implements WithdrawalLimitBizService {

    @Autowired
    private ConfServiceImpl confService;

    @Override
    public ConfConst.Code getCode() {
        return ConfConst.Code.WITHDRAWAL_LIMIT;
    }

    @Override
    @UseRedis(value = REDIS_CACHE_PREFIX, clazz = WithdrawalLimitRes.class, timeout = TIMEOUT, timeUnit = TimeUnit.HOURS)
    public WithdrawalLimitRes get() {
        WithdrawalLimit rule = confService.getRule(ConfConst.Code.WITHDRAWAL_LIMIT, WithdrawalLimit.class);
        return BeanUtil.toBean(rule, WithdrawalLimitRes.class);
    }

    @Override
    @ClearRedis(value = REDIS_CACHE_PREFIX, clazz = WithdrawalLimitRes.class)
    public boolean update(WithdrawalLimitReq withdrawalLimitReq) {
        return confService.updateRule(withdrawalLimitReq, ConfConst.Code.WITHDRAWAL_LIMIT, WithdrawalLimit.class);
    }
}
